<style lang="scss" scoped="">
  @import "../../utils/base.scss";
</style>
<template>
  <div>
  	<pheader style="border-bottom: 1px solid #dcdae2; ">
  		<div slot="left">BI报表</div>
  	</pheader>
  	<tabContent>
  		<template slot="content" style="position: relative;">
  			<Table ref="table" :columns="columns" :max-height="tableHeight" :data="data" border style="margin-right:1px">
  			  <template slot-scope="{ row, index }" slot="action">
  			  		<div style="display: inline-block;">
  			  			<a href="javascript:void(0)" @click="showinfo(row)">
  			  				<div class="text_link" style="width: 50px;">
  			  					查看
  			  				</div>
  			  			</a>
  			      </div>
  			  </template>
  			</Table>
  		</template>
  	</tabContent>
  </div>

</template>

<script>
  import pheader from "../../comp_chatter/pheader"
  import ajax from "../../ajax_util"
  import tabContent from "../../comp_chatter/tab_content.vue"

  export default {
    components: {
      pheader,tabContent
    },
    data() {
      return {
        tabs: null,
        tableHeight: 600,
        data: [],
        columns:[
          {
            title: '报表名称',
            key: 'rname',
            align: 'left',
          },
          {
            title: '更新时间',
            key: 'updateTime',
            align: 'left',
            width: 200
          },
          {
            title: '操作',
            key: 'action',
            align: 'left',
            width: 110,
            slot: "action"
          }
        ]
      }
    },
    created:function(){
      this.tabs = this.$store.state.tabs
      this.tableHeight = window.innerHeight - 120
      this.getBiReport()
    },

    mounted() {},

    methods: {
      showinfo(row){
        var reportUrl = this.CONFIG.BIReport_url + "/ureport/preview?_u=" +row.prefix + "." + row.rname + ".ureport.xml&_i=1&_r=1"

        var isName = false //是否已经存在标签
        var key = row.prefix + "." + row.rname + ".ureport.xml"
        this.tabs.list.some(item => {
        	if (item.tabKey === key) {
        		isName = true
        		return
        	}
        })

        if (!isName) {
        	this.tabs.list.push({
        		title: row.rname + "数据统计报表",
        		key: "BIReportInfo",
        		tabKey: key,
        		params: {
        			reportUrl: reportUrl,
        		}
        	})
        }
        this.tabs.isEdit = ""
        this.tabs.lastPage = this.tabs.tabsPage
        this.tabs.tabsPage = key
        this.$store.commit("tabs", this.tabs);
      },
      getBiReport(){
        var that = this;
        var url = this.CONFIG.BIReport_url + "/manage/getBiReport";
        var params = {
          status: "published"
        }
        ajax.get({
        	url: url,
        	that: that,
          params: params,
        	success: function(data) {
        		that.data = data;
        	}
        })
      }
    }
  }
</script>
